# -*- coding:utf-8 -*-
import threading
from queue import Queue
from random import choice
import time

dealList = ["红烧猪蹄", "卤鸡爪", "酸菜鱼", "糖醋里脊", "九转大肠", "阳春面", "烤鸭", "烧鸡", "剁椒鱼头", "酸汤肥牛",
            "炖羊肉"]

queue = Queue(maxsize=5)


# 厨子生产
def func_one(name):
    for num in range(4):
        # 随机从列表当中获取一个元素
        data_veg = choice(dealList)
        queue.put(data_veg, block=True)
        print(f"厨师{name}给大家做了一道：{data_veg}")
        time.sleep(1)


# 客人消费
def func_two(name):
    for num in range(3):
        veg_data = queue.get()
        print(f"{name}吃掉了:{veg_data}")
        queue.task_done()
        time.sleep(1)


if __name__ == '__main__':
    # 创建生产者线程，总共三个厨子,相当于给每个厨子创建了一个线程
    # 使用了循环创建线程
    for name in ["张三", "李四", "王五"]:
        thread_one = threading.Thread(target=func_one, args=(name,))
        thread_one.start()
    # 创建消费者四个线程
    for name in ["客人甲", "客人乙", "坤哥", "凡哥"]:
        thread_two = threading.Thread(target=func_two, args=(name,))
        thread_two.start()
    queue.join()
